﻿using System;
using BLL;
using Utils;
namespace UI.ModEmployee
{
    public partial class EmpRewardsStatistic : System.Web.UI.Page
    {
        EmpRewardsBiz empRewardsBiz = new EmpRewardsBiz();
        EmployeeBiz employeeBiz = new EmployeeBiz();
        string account = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] != null)
            {
                User user = Session["user"] as User;
                account = user.Account;
            }
            else
            {
                JSUtility.Alert(this, "您没有登录!请先登录。");
                return;
            }
            if (!IsPostBack)
            {
                txtBtime.Text =  System.DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
                txtEtime.Text = System.DateTime.Now.ToString("yyyy-MM-dd");
            }

        }

        protected void btnSalesman_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "EmpRewardsStatistic.aspx", RightChar.Ser))
            {
                JSUtility.Alert(this, "无权限！");
                return;
            }
            string caption = "<b>按售货员统计人数</b><br />";
            gvList.Caption = caption;
           string typeName= ddlType.SelectedValue;
           string bTime = txtBtime.Text.Trim();
           string eTime = txtEtime.Text.Trim();
           gvList.DataSource = empRewardsBiz.GetStatisticByEmp(typeName, bTime, eTime);
           gvList.DataBind();
        }

        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "EmpRewardsStatistic.aspx", RightChar.Ser))
            {
                JSUtility.Alert(this, "无权限！");
                return;
            }
            string caption = "<b>按部门统计人数</b><br />";
            gvList.Caption = caption;           
            string typeName = ddlType.SelectedValue;
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            gvList.DataSource = empRewardsBiz.GetStatisticByDept(typeName, bTime, eTime);
            gvList.DataBind();
        }

        //根据gridview打印
        protected void btnPrint_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "EmpRewardsStatistic.aspx", RightChar.Print))
            {
                JSUtility.Alert(this, "无权限！");
                return;
            }
            ToolUtility.Printer("按雇员统计表", gvList);
        }
      
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "EmpRewardsStatistic.aspx", RightChar.Out))
            {
                JSUtility.Alert(this, "无权限！");
                return;
            }
            ExcelUtility.GridViewToExcel(gvList, "EmpStati.xls");
         }
    }
}